<div class="col-lg-12">
    <section class="panel">
        <header class="panel-heading">
            添加门店/部门(Branch/Part)
        </header>
        <div class="panel-body">
            <div class="position-center">
                <form action="/index/category/cate_deal_add"role="form" method="post" id="f_form">
                <div class="form-group">
                    <label for="exampleInputPassword1">门店/部门(Branch/Part)</label>
                    <input type="hidden" name="id" value="{$data['id']}">
                    <input name="name" type="text" value="{$data['name']}" class="form-control" id="exampleInputPassword1" {if condition="$data[id]"}disabled{/if}><p class="help-block name"></p>
                </div>
                <div class="form-group">
                    <label for="exampleInputPassword1">所属门店(Parent Branch)</label>
                    <select name="parent"  class="form-control" id="exampleInputPassword1" >
                        <option value="0" {if condition="$data[parent_id] eq 0"}selected{/if}>--无(NONE)--</option>
  
                        <option value="{$data1.id}"   {if condition="$data[parent_id] eq 1"}selected{/if}>--{$data1.name}--</option>
    
                    </select>    
                </div>
                {if condition="!$data[id]"}
                <div class="form-group">
                    <label for="exampleInputPassword1">用户名(Username)</label>
                    <input name="username" type="text" value=" " class="form-control" id="exampleInputPassword1">
                    <p class="help-block uname"></p>
                </div>
                <div class="form-group">
                    <label for="exampleInputPassword1">用户密码(Password)</label>
                    <input name="pwd" type="password" value="" class="form-control" id="exampleInputPassword1" >
                </div>
                {else:}
                 <div class="form-group">
                    <label for="exampleInputPassword1">用户名(Username)</label>
                    <input name="username" type="text" value="{$data.username}" class="form-control" id="exampleInputPassword1" disabled>
                    <p class="help-block uname"></p>
                </div>
                <div class="form-group">
                    <label for="exampleInputPassword1">用户密码(Password)</label>
                    <input name="pwd" type="password" value="" class="form-control" id="exampleInputPassword1" >
                </div>               
                {/if}

                <button type="button" class="btn btn-info sub">Submit</button>
            </form>
            </div>

        </div>
    </section>
    <script type="text/javascript">
    $(function(){
        var flag=2;
        $("input[name='name']").change(function(){
            if($(this).val()==''||$(this).val()=='undefined'){
                return;
            }
             var url='/index/category/cate_check/id/{$data.id}'
            $.post(url, { name: $(this).val()},function(data){
                if(data.status=='0'){
                    flag=2;
                    $(".name").html('')
                }else{
                    $(".name").html('部门已存在')
                    flag=1
                }
            },'json');              
        })
        $("input[name='username']").change(function(){
            if($(this).val()==''||$(this).val()=='undefined'){
                return;
            }
             var url='/index/category/cate_check/id/{$data.id}'
            $.post(url, { uname: $(this).val()},function(data){
                if(data.status=='0'){
                    flag=2;
                    $(".uname").html('')
                }else{
                    $(".uname").html('用户名已存在')
                    flag=1
                }
            },'json');              
        })
        $(".sub").click(function(){
            if($("input[name='name']").val()==''||$("input[name='name']").val()=='undefined'||$("input[name='username']").val()==''||$("input[name='username']").val()=='undefined'){
                return;
            }
            if(flag==2)
                $("#f_form").submit();           
        })
    })

    </script>
</div>